// 
// Decompiled by Procyon v0.5.36
// 

package com.cyberfend.cyfsecurity;

import android.os.*;
import com.cyberfend.cyfsecurity.b.*;
import com.cyberfend.cyfsecurity.a.*;
import android.util.*;
import java.security.interfaces.*;
import java.security.*;
import javax.crypto.spec.*;
import javax.crypto.*;

final class ad
{
    private static final com.cyberfend.cyfsecurity.ad a;
    private javax.crypto.SecretKey b;
    private javax.crypto.SecretKey c;
    private java.lang.String d;
    private java.lang.String e;
    
    ad() {
        this.b = null;
        this.c = null;
    }
    
    public static com.cyberfend.cyfsecurity.ad a() {
        return com.cyberfend.cyfsecurity.ad.a;
    }
    
    private final synchronized void b() {
        try {
            if (this.b != null && this.c != null) {
                return;
            }
            final long uptimeMillis = android.os.SystemClock.uptimeMillis();
            com.cyberfend.cyfsecurity.b.a.a("SensorDataBuilder", "Initializing keys", new java.lang.Throwable[0]);
            final javax.crypto.KeyGenerator instance;
            (instance = javax.crypto.KeyGenerator.getInstance("AES")).init(128);
            this.b = instance.generateKey();
            final javax.crypto.KeyGenerator instance2;
            (instance2 = javax.crypto.KeyGenerator.getInstance("HmacSHA256")).init(256);
            this.c = instance2.generateKey();
            android.os.SystemClock.uptimeMillis();
            final java.security.interfaces.RSAPublicKey a = com.cyberfend.cyfsecurity.a.b.a("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4sA7vA7N/t1SRBS8tugM2X4bByl0jaCZLqxPOql+qZ3sP4UFayqJTvXjd7eTjMwg1T70PnmPWyh1hfQr4s12oSVphTKAjPiWmEBvcpnPPMjr5fGgv0w6+KM9DLTxcktThPZAGoVcoyM/cTO/YsAMIxlmTzpXBaxddHRwi8S2NvwIDAQAB");
            final byte[] a2 = com.cyberfend.cyfsecurity.a.b.a(this.b.getEncoded(), a);
            final byte[] a3 = com.cyberfend.cyfsecurity.a.b.a(this.c.getEncoded(), a);
            android.os.SystemClock.uptimeMillis();
            this.d = android.util.Base64.encodeToString(a2, 2);
            this.e = android.util.Base64.encodeToString(a3, 2);
            com.cyberfend.cyfsecurity.b.a.a("SensorDataBuilder", "InitializeKeys-Time: " + (android.os.SystemClock.uptimeMillis() - uptimeMillis) + "ms", new java.lang.Throwable[0]);
        }
        catch (java.lang.Exception ex) {}
    }
    
    public final synchronized java.lang.String a(java.lang.String s) throws java.lang.Exception {
        try {
            if (this.b == null || this.c == null) {
                this.b();
            }
            final long uptimeMillis = android.os.SystemClock.uptimeMillis();
            com.cyberfend.cyfsecurity.b.a.a("SensorDataBuilder", "Building sensor data, plain data size: " + s.length(), new java.lang.Throwable[0]);
            final long uptimeMillis2 = android.os.SystemClock.uptimeMillis();
            final javax.crypto.Cipher instance;
            (instance = javax.crypto.Cipher.getInstance("AES/CBC/PKCS5Padding")).init(1, this.b);
            final byte[] doFinal = instance.doFinal(s.getBytes());
            final long n = (android.os.SystemClock.uptimeMillis() - uptimeMillis2) * 1000L;
            final byte[] iv = instance.getIV();
            final byte[] array = new byte[doFinal.length + iv.length];
            java.lang.System.arraycopy(iv, 0, array, 0, iv.length);
            java.lang.System.arraycopy(doFinal, 0, array, iv.length, doFinal.length);
            final javax.crypto.spec.SecretKeySpec secretKeySpec = new javax.crypto.spec.SecretKeySpec(this.c.getEncoded(), "HmacSHA256");
            final long uptimeMillis3 = android.os.SystemClock.uptimeMillis();
            final javax.crypto.Mac instance2;
            (instance2 = javax.crypto.Mac.getInstance("HmacSHA256")).init(secretKeySpec);
            final byte[] doFinal2 = instance2.doFinal(array);
            final long n2 = (android.os.SystemClock.uptimeMillis() - uptimeMillis3) * 1000L;
            final byte[] array2 = new byte[array.length + doFinal2.length];
            java.lang.System.arraycopy(array, 0, array2, 0, array.length);
            java.lang.System.arraycopy(doFinal2, 0, array2, array.length, doFinal2.length);
            final long uptimeMillis4 = android.os.SystemClock.uptimeMillis();
            s = android.util.Base64.encodeToString(array2, 2);
            final long n3 = (android.os.SystemClock.uptimeMillis() - uptimeMillis4) * 1000L;
            new java.lang.StringBuilder("Encrypted size: ").append(array2.length);
            final java.lang.Throwable[] array3 = new java.lang.Throwable[0];
            new java.lang.StringBuilder("Base64 Encrypted size: ").append(s.length());
            final java.lang.Throwable[] array4 = new java.lang.Throwable[0];
            new java.lang.StringBuilder("AEStime: ").append(n).append(", HMACtime: ").append(n2).append(", B64time: ").append(n3);
            final java.lang.Throwable[] array5 = new java.lang.Throwable[0];
            s = "1,a," + this.d + "," + this.e + "$" + s + "$" + (n + "," + n2 + "," + n3);
            com.cyberfend.cyfsecurity.b.a.a("SensorDataBuilder", "Cipher-BuildSensorData-Time: " + (android.os.SystemClock.uptimeMillis() - uptimeMillis) + "ms", new java.lang.Throwable[0]);
            return s;
        }
        catch (java.lang.Exception ex) {
            throw ex;
        }
    }
    
    static {
        a = new com.cyberfend.cyfsecurity.ad();
    }
}
